﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Easily
{
    public partial class frmFunDefine : Form
    {
        #region 对外的属性和私有成员
        /// <summary>
        /// 存储传入的图标控件
        /// </summary>
        private GeneralIcon MyIcon = null;
        #endregion

        #region 构造函数和对外的方法
        /// <summary>
        /// 类的构造函数
        /// 功能概要：保存控件对象；设置默认延时1000毫秒
        /// </summary>
        /// <param name="icon"></param>
        public frmFunDefine(GeneralIcon icon)
        {
            InitializeComponent();
            this.MyIcon = icon;
            if(this.MyIcon.code.Save != "")
            {
                this.txt_funName.Text = this.MyIcon.code.Save;
                this.createCode();
            }
        }
        #endregion

        #region 事件
        /// <summary>
        /// 点击“确定”按钮
        /// 功能概要：设置延时
        /// </summary>
        private void buttonEnsure_Click(object sender, EventArgs e)
        {
            this.createCode();
            this.DialogResult = DialogResult.OK;//表示当窗体用作对话框时该窗体的结果，
            this.Close();
        }
        /// <summary>
        /// 单击“取消”按钮
        /// 主要功能：设置返回结果为取消
        /// </summary>
        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
        /// <summary>
        /// 点击“注释说明”按钮
        /// 功能概要：为控件添加自定义注释说明
        /// </summary>
        private void btn_comment_Click(object sender, EventArgs e)
        {
            using (frmNodeEditer NE = new frmNodeEditer(this.MyIcon.code.Comment))
            {
                if (NE.ShowDialog() == DialogResult.OK)
                    this.MyIcon.code.Comment = NE.NoteEdit;
            }
        }
        #endregion
        #region 内部函数
        /// <summary>
        /// 创建生成的代码
        /// </summary>
        private void createCode()
        {
            try
            {
                //添加头文件、初始化代码等
                MyIcon.code.Clear();//清空以前代码
                MyIcon.code.SubfunctionDeclare = "void " + txt_funName.Text + "(void);//声明函数";
                MyIcon.code.SubfunctionStart = "void " + txt_funName.Text + "(void)\r\n{\r\n";
                MyIcon.code.SubfunctionEnd = "}";
                MyIcon.code.Comment = "定义函数：" + txt_funName.Text ;
                MyIcon.code.Save = txt_funName.Text;
                MyIcon.code.InsertCode = "";
                //MyIcon.code.Save = milliSecond.ToString();
            }
            catch { }
        }
        #endregion
    }
}
